<template>
	<view class="container">
		<!-- 顶部选项卡 -->
		<view class="swiper-tab dis-flex box-align-center flex-y-center">
			<view class="swiper-tab-item " :class="[dataType === 'not_use' ? 'on' : '']" data-current="not_use" @tap="swichNav">未使用</view>
			<view class="swiper-tab-item " :class="[dataType === 'is_use' ? 'on' : '']" data-current="is_use" @tap="swichNav">已使用</view>
			<view class="swiper-tab-item " :class="[dataType === 'is_expire' ? 'on' : '']" data-current="is_expire" @tap="swichNav">已过期</view>
		</view>

		<scroll-view scroll-y="true" :style="[{'height' : Height}]">
			<view class="coupon-list" v-if="list.length">
				<view class="coupon-item" v-for="(item,index) in list" :key="index">
					<view class="item-wrapper" :class="['color__' + item.color.text]">
						<view class="coupon-type">{{ item.coupon_type.text }}</view>
						<view class="tip dis-flex flex-dir-column flex-x-center">
							<view v-if="item.coupon_type.value == 10">
								<text class="f-30">￥</text>
								<text class="money">{{ item.reduce_price }}</text>
							</view>
							<text class="money" v-if="item.coupon_type.value == 20">{{ item.discount }}折</text>
							<text class="pay-line">满{{ item.min_price }}元可用</text>
						</view>
						<view class="split-line"></view>
						<view class="content dis-flex flex-dir-column flex-x-between">
							<view class="title">{{ item.name }}</view>
							<view class="bottom dis-flex flex-y-center">
								<view class="time flex-box">
									<text class="f-24">{{ item.start_time.text }}~{{ item.end_time.text }}</text>
								</view>
								<view class="state">
									<text class="f-24">{{ item.state.text }}</text>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="yoshop-notcont" v-else-if="notcont">
				<text class="iconfont icon-wushuju"></text>
				<text class="cont">亲，暂无优惠券哦</text>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		computed: {
			Height() {
				return uni.upx2px(this.swiperHeight * 2) + 'px';
			}
		},
		data() {
			return {
				// 选项卡标示
				dataType: 'not_use',

				// 列表高度
				swiperHeight: 0,

				// 优惠券列表
				list: [],

				// show
				notcont: false
			}
		},

		/**
		 * 生命周期函数--监听页面加载
		 */
		onLoad: function(options) {
			// 设置swiper的高度
			this.setSwiperHeight();
		},

		/**
		 * 生命周期函数--监听页面显示
		 */
		onShow: function() {
			// 获取优惠券列表
			this.getCouponList();
		},

		methods: {

			/**
			 * 获取优惠券列表
			 */
			getCouponList: function() {
				let _this = this;
				_this._get('user.coupon/lists', {
					data_type: _this.dataType
				}, function(result) {
					_this.setData({
						list: result.data.list,
						notcont: !result.data.list.length
					});
				});
			},

			/**
			 * 设置swiper的高度
			 */
			setSwiperHeight: function() {
				// 获取系统信息(拿到屏幕宽度)
				let systemInfo = uni.getSystemInfoSync(),
					upx = systemInfo.windowWidth / 750, // 计算upx
					tapHeight = Math.floor(upx * 80) + 1, // tap高度
					swiperHeight = systemInfo.windowHeight - tapHeight; // swiper高度
				this.setData({
					swiperHeight
				});
			},

			/** 
			 * 点击tab切换 
			 */
			swichNav: function(e) {
				let _this = this;
				_this.setData({
					list: [],
					dataType: e.target.dataset.current
				});
				_this.getCouponList();
			},
		}
	}
</script>

<style>
	@charset "UTF-8";

	/* 选项卡 */
	.swiper-tab {
		width: 100%;
		text-align: center;
		height: 80upx;
		background-color: #fff;
		border-bottom: 1px solid #eee;
	}

	.swiper-tab .swiper-tab-item {
		width: 33.333333%;
		height: 100%;
		font-size: 28upx;
		color: #777;
		display: flex;
		justify-content: center;
		align-items: center;
		box-sizing: border-box;
		border-bottom: 2px solid #ffffff00;
	}

	.swiper-tab .on {
		color: #f74c45;
		border-bottom: 2px solid #f74c45;
	}

	/* 设置scroll-view容器高度 */
	.coupon-list,
	.yoshop-notcont {
		height: 100.1%;
	}

	/* 评论列表 */
	.coupon-list {
		padding: 20upx;
		box-sizing: border-box;
	}

	.coupon-list .coupon-item {
		position: relative;
		overflow: hidden;
		margin-bottom: 22upx;
	}

	.coupon-list .coupon-item .item-wrapper {
		width: 100%;
		display: flex;
		background: #fff;
		border-radius: 8upx;
		color: #fff;
		height: 180upx;
	}

	.coupon-list .coupon-item .item-wrapper .coupon-type {
		position: absolute;
		top: 0;
		right: 0;
		z-index: 10;
		width: 128upx;
		padding: 3px 0;
		background: #a771ff;
		font-size: 20upx;
		text-align: center;
		color: #ffffff;
		transform: rotate(45deg);
		transform-origin: 64upx 64upx;
	}

	.coupon-list .coupon-item .item-wrapper.color__blue {
		background: linear-gradient(-125deg, #57bdbf, #2f9de2);
	}

	.coupon-list .coupon-item .item-wrapper.color__red {
		background: linear-gradient(-128deg, #ff6d6d, #ff3636);
	}

	.coupon-list .coupon-item .item-wrapper.color__violet {
		background: linear-gradient(-113deg, #ef86ff, #b66ff5);
	}

	.coupon-list .coupon-item .item-wrapper.color__violet .coupon-type {
		background: #55b5ff;
	}

	.coupon-list .coupon-item .item-wrapper.color__yellow {
		background: linear-gradient(-141deg, #f7d059, #fdb054);
	}

	.coupon-list .coupon-item .item-wrapper.color__gray {
		background: linear-gradient(-113deg, #bdbdbd, #a2a1a2);
	}

	.coupon-list .coupon-item .item-wrapper.color__gray .coupon-type {
		background: #9e9e9e;
	}

	.coupon-list .coupon-item .item-wrapper .content {
		flex: 1;
		padding: 30upx 20upx;
		border-radius: 8px 0 0 8px;
	}

	.coupon-list .coupon-item .item-wrapper .content .title {
		font-size: 38upx;
	}

	.coupon-list .coupon-item .item-wrapper .tip {
		position: relative;
		flex: 0 0 32%;
		text-align: center;
		border-radius: 0 8px 8px 0;
	}

	.coupon-list .coupon-item .item-wrapper .tip .money {
		font-weight: bold;
		font-size: 52upx;
	}

	.coupon-list .coupon-item .item-wrapper .tip .pay-line {
		font-size: 22upx;
	}

	.coupon-list .coupon-item .item-wrapper .split-line {
		position: relative;
		flex: 0 0 0;
		border-left: 4upx solid #fff;
		margin: 0 5px 0 3px;
		background: #fff;
	}

	.coupon-list .coupon-item .item-wrapper .split-line:before,
	.coupon-list .coupon-item .item-wrapper .split-line:after {
		content: '';
		position: absolute;
		width: 12px;
		height: 6px;
		background: #f7f7f7;
		left: -7px;
		z-index: 1;
	}

	.coupon-list .coupon-item .item-wrapper .split-line:before {
		border-radius: 0 0 8px 8px;
		top: 0;
	}

	.coupon-list .coupon-item .item-wrapper .split-line:after {
		border-radius: 8px 8px 0 0;
		bottom: 0;
	}

	/* 没有更多 */
	.no-more {
		text-align: center;
		color: #737373;
		padding: 10px 0;
	}

	/*# sourceMappingURL=coupon.wxss.map */
</style>
